<?php

namespace App\Http\Controllers\Admin;

use App\Admin\Subject;
use App\Http\Controllers\Controller;
use App\Http\Requests\SubjectRequest;
use App\Repositories\SubjectRepositories;
use Illuminate\Http\Request;

class SubjectController extends Controller
{
    protected $repo;

    public function __construct(SubjectRepositories $repo)
    {
        $this->repo = $repo;
    }

    public function index()
    {
        return view('admin.subject');
    }

    public function store(SubjectRequest $request)
    {
        return $this->repo->save($request) ? '1' : '0';
    }

    public function show(Subject $subject)
    {
        return view('admin.subject_add', compact('subject'));
    }

    public function destroy(Subject $subject)
    {
        return $subject->delete() ? '1' : '0';
    }

    public function edit(Subject $subject)
    {
        return view('admin.subject_edit', compact('subject'));
    }

    public function update(Subject $subject, SubjectRequest $request)
    {
        $data = $request->only(['name', 'id']);
        return $subject->update($data) ? '1' : '0';
    }

}
